<?php
namespace Home\Controller;
use Think\Controller;
class UController extends CommonController {
    public function index(){
        // $id=I('get.id');
        $sql="select t2.* from user t1 inner join question t2 on t1.id=t2.uid where t1.id='{$_SESSION['id']}'";
       
      $self= M('user')->query($sql);
      // var_dump($self);
      $this->assign('self',$self);
       $this->display();
    }
    

    public function main(){
        if (empty(I('get.id')) and empty($_SESSION['id']) ){
        $this->error('不好意思,请登录',U('home/index/index'));
        }else{
                	if (!empty(I('get.id'))) {
                		$id=I('get.id');
                	}else{
                		$id=$_SESSION['id'];
                	}
                    
                    $sql="select * from user where id='{$id}'";
                       
                    $user =M()->query($sql);
                    $user=current($user);
                    
                    $this->assign('user',$user);
                     
                    $sql="select * from question where uid='{$id}'";
                    $question =M()->query($sql);      
                    $this->assign('question',$question);
                     
                    $sql="select t1.title ,t1.id,t2.create_time,t2.content  from question t1 inner join answer t2 on t1.id = t2.qid  where t2.uid={$id}";
                    $answer=M()->query($sql);
                   
                    $this->assign('answer',$answer);
                    

                     $this->display();
            }
    }


    public function find_nickname(){
         $nickname=I('get.nickname');
        $res=M('user')->where(array('nickname'=>$nickname))->find();
        $id=$res['id'];
        $url=U('home/u/main',array('id'=>$id));
        header('location:'.$url);
    }


}